<template>
  <div class="picking zy-content">
    <div class="searchBox search-box-layout">
      <Row :gutter="24">
        <Col span="4">
          <div>
            <p class="label">验收状态:</p>
            <div class="ipt">
              <Select
                v-model="searchParams.checkAcceptState"
                clearable
                :placeholder="`${$t('common.selectInfo')}`"
                class="Input-wrapper"
              >
                <Option
                  v-for="(item) of checkAcceptStateList"
                  :value="item.label"
                  :key="item.value"
                  :label="item.label"
                ></Option>
              </Select>
            </div>
          </div>
        </Col>
        <Col span="4">
          <div>
            <p class="label">设备编号:</p>
            <div class="ipt">
              <Input
                type="text"
                clearable
                v-model="searchParams.deviceCode"
                :placeholder="`${$t('common.inputInfo')}`"
                class="inputBorder"
                :maxlength="32"
              ></Input>
            </div>
          </div>
        </Col>
        <Col span="4">
          <div>
            <p class="label">设备名称:</p>
            <div class="ipt">
              <Input
                type="text"
                clearable
                v-model="searchParams.deviceName"
                :placeholder="`${$t('common.inputInfo')}`"
                class="inputBorder"
                :maxlength="32"
              ></Input>
            </div>
          </div>
        </Col>
        <Col span="4">
          <div>
            <p class="label">资产编号</p>
            <div class="ipt">
              <Input
                clearable
                type="text"
                v-model="searchParams.assetCode"
                :placeholder="`${$t('common.inputInfo')}`"
                class="inputBorder"
                :maxlength="32"
              ></Input>
            </div>
          </div>
        </Col>
        <Col span="4">
          <div>
            <p class="label">验收人</p>
            <div class="ipt">
              <Input
                clearable
                type="text"
                v-model="searchParams.name1"
                :placeholder="`${$t('common.inputInfo')}`"
                class="inputBorder"
                :maxlength="32"
              ></Input>
            </div>
          </div>
        </Col>
        <Col span="4">
          <div>
            <p class="label">所属公司</p>
            <div class="ipt">
              <Select
                v-model="searchParams.company"
                filterable
                clearable
                :placeholder="`${$t('common.selectInfo')}${$t('preliminary.Buyer')}`"
                :remote-method="getOAList"
                class="Input-wrapper"
              >
                <Option
                  v-for="(item) of OAList"
                  :value="item.id"
                  :key="item.id"
                  :label="item.showName"
                ></Option>
              </Select>
            </div>
          </div>
        </Col>
        <Col span="4">
          <div>
            <p class="label">验收日期:</p>
            <div class="ipt">
              <DatePicker
                type="daterange"
                placement="bottom-end"
                :value="dateTimeRange"
                :placeholder="`${$t('common.selectInfo')}`"
                clearable
                @on-change="handleChangeDate"
              ></DatePicker>
            </div>
          </div>
        </Col>
        <Col span="4">
          <div>
            <p class="label hide-label">--</p>
            <div class="ipt">
              <Button type="primary" class="search-btn" @click="changeNum()">
                {{
                $t('common.Query') }}
              </Button>
              <Button class="reset-btn" @click="reset()">{{ $t('common.reset') }}</Button>
            </div>
          </div>
        </Col>
      </Row>
    </div>
    <div class="list-layout mt16">
      <div class="btns clear">
        <span class="title">{{ $t('common.listInformation') }}</span>
        <Button
          @click="exportTemplateClick"
          v-has="'dmsPurchaseExport'"
        >{{ $t('maintenance.Export') }}</Button>
      </div>
      <div class="tableContent">
        <Table
          ellipsis
          class="resizable-table"
          ref="selection"
          :border="false"
          :columns="orderAdjustmentDeviceInfoList"
          :data="dataSource"
          @on-selection-change="handleSelectionChange"
          @on-column-width-resize="(a,b,c,d)=>{onColumnWidthResize(a,b,c,d,'orderAdjustmentDeviceInfo')}"
        >
          <template slot-scope="{ row }" slot="action">
            <span
              class="operationBtn"
              @click="addClickinfo(row, false)"
              v-if="row.checkAcceptState !== '已录入' && row.checkAcceptState !== '已完成'"
            >
              <i class="iconfont zy-common-neirong"></i>
              {{ $t('preliminary.PurchasingKeyIn') }}
            </span>
            <span class="operationBtn" @click="addClickinfo(row, true)">
              <i class="iconfont zy-common-chakan"></i>
              {{ $t('common.Check') }}
            </span>
            <span
              class="operationBtn"
              @click="clickRow(row, 'comp')"
              v-if="row.checkAcceptState == '已录入'"
            >完成</span>
            <span
              class="operationBtn"
              @click="clickRow(row, 'rej')"
              v-if="row.checkAcceptState == '已录入'"
            >驳回</span>
          </template>
        </Table>
      </div>
      <div class="pageWrap mt16">
        <pageLeftTitle :total="total" :selected="ids.length" />
        <Page
          :total="total"
          :page-size="pageSize"
          :page-size-opts="$variable.pageSizes"
          :current="pageNum"
          @on-change="changePageNum"
          @on-page-size-change="changePageSize"
          show-sizer
          show-total
        />
      </div>
    </div>
    <!--采购录入-->
    <add-purchase-modal ref="addPurchaseModal" @refresh="handleRefresh" />

    <Modal
      :title="checkInfo ? '查看' : textInfo"
      width="1150px"
      class="modal-content-layout"
      @on-visible-change="addViseChange"
      v-model="addStatus"
      :mask-closable="false"
    >
      <Form
        ref="purchaseForm"
        :rules="addPurchaseFormRule"
        label-position="top"
        :model="purchaseList"
        :disabled="checkInfo"
      >
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="管理部门" prop="dhzt">
              <Select v-model="purchaseList.deptId" clearable>
                <Option v-for="val in deptList" :value="val.id" :key="val.id" :label="val.deptName"></Option>
              </Select>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="设备编号" prop="deviceNo">
              <Input
                v-model="purchaseList.deviceNo"
                :placeholder="`${$t('common.inputInfo')}设备编号`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="设备评分" prop="score">
              <InputNumber
                style="width:100%"
                :max="100"
                :min="0"
                v-model="purchaseList.score"
                :placeholder="`${$t('common.inputInfo')}设备评分`"
              ></InputNumber>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="设备名称" prop="deviceName">
              <Input
                readonly
                v-model="purchaseList.deviceName"
                :placeholder="`${$t('common.inputInfo')}设备名称`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="设备英文名" prop="deviceEnglish">
              <Input
                v-model="purchaseList.deviceEnglish"
                :placeholder="`${$t('common.inputInfo')}设备英文名`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="设备类别" prop="deviceCategory">
              <Select
                v-model="purchaseList.deviceCategory"
                filterable
                clearable
                :placeholder="`${$t('common.selectInfo')}设备类别`"
              >
                <Option v-for="val in deviceType" :value="val.value" :key="val" :label="val.value"></Option>
              </Select>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="规格型号" prop="specModel">
              <Input
                readonly
                v-model="purchaseList.specModel"
                :placeholder="`${$t('common.inputInfo')}规格型号`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="设备来源" prop="deviceSource">
              <Select
                v-model="purchaseList.deviceSource"
                filterable
                clearable
                :placeholder="`${$t('common.selectInfo')}设备来源`"
              >
                <Option
                  v-for="val in deviceSource"
                  :value="val.value"
                  :key="val.id"
                  :label="val.value"
                ></Option>
              </Select>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="安装部门" prop="installDept">
              <Input
                v-model="purchaseList.installDept"
                :placeholder="`${$t('common.inputInfo')}安装部门`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="安装时间" prop="installTime">
              <Date-picker
                :value="purchaseList.installTime"
                @on-change="(val) => {
                            purchaseList.installTime = val
                        }"
                type="date"
                value-format="yyyy-MM-dd"
                :placeholder="`${$t('common.selectInfo')}安装时间`"
              />
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="功能位置" prop="functionLocation">
              <cascaderMulti
                :disabled="checkInfo"
                clearable
                ref="cascader"
                :data="orgList"
                v-model="purchaseList.functionLocation"
                placeholder="请选择"
              ></cascaderMulti>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="设备用途" prop="deviceUseto">
              <Input
                v-model="purchaseList.deviceUseto"
                :placeholder="`${$t('common.inputInfo')}设备用途`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="验收日期" prop="checkAcceptDate">
              <Date-picker
                :value="purchaseList.checkAcceptDate"
                @on-change="(val) => {
                            purchaseList.checkAcceptDate = val
                        }"
                type="date"
                value-format="yyyy-MM-dd"
                :placeholder="`${$t('common.selectInfo')}验收日期`"
              />
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="出厂编号" prop="factoryNo">
              <Input
                v-model="purchaseList.factoryNo"
                :placeholder="`${$t('common.inputInfo')}出厂编号`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="制造日期" prop="manufacturDate">
              <Date-picker
                :value="purchaseList.manufacturDate"
                type="date"
                @on-change="(val) => {
                            purchaseList.manufacturDate = val
                        }"
                format="yyyy-MM-dd"
                :placeholder="`${$t('common.selectInfo')}制造日期`"
              />
            </Form-item>
          </Col>

          <!-- <Col :span="8">
                    <Form-item :label="`${$t('preliminary.PurchasingContract')}`" prop="purchaseContract">
                        <Upload ref="fileUpload" :show-upload-list="false" :before-upload="handleBeforeUpload" type="drag"
                            action="">
                            <Button type="primary">{{ $t('common.Upload') }}</Button>
                        </Upload>
                        <div>
                            <Tag color="blue" type="border" closable @on-close="delFileList(index)"
                                v-for="(item, index) in setFileList" :key="index">
                                {{ item.fileName }}
                            </Tag>
                        </div>
                    </Form-item>
          </Col>-->
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="制造商" prop="manufacture">
              <Input
                v-model="purchaseList.manufacture"
                :placeholder="`${$t('common.inputInfo')}制造商`"
                type="text"
              ></Input>
            </Form-item>
          </Col>

          <Col :span="8">
            <Form-item label="电源电压(V)" prop="voltage">
              <Input
                v-model="purchaseList.voltage"
                :placeholder="`${$t('common.inputInfo')}电源电压`"
                type="text"
              ></Input>
            </Form-item>
          </Col>

          <Col :span="8">
            <Form-item label="额定功率(kw)" prop="devicePower">
              <Input
                v-model="purchaseList.devicePower"
                :placeholder="`${$t('common.inputInfo')}额定功率`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="设备重量" prop="deviceWeight">
              <Input
                style="width: 100%;"
                v-model="purchaseList.deviceWeight"
                :placeholder="`${$t('common.inputInfo')}设备重量`"
              ></Input>
            </Form-item>
          </Col>

          <Col :span="8">
            <Form-item label="生产线描述" prop="productionLineDescription">
              <Input
                v-model="purchaseList.productionLineDescription"
                :placeholder="`${$t('common.inputInfo')}生产线描述`"
              ></Input>
            </Form-item>
          </Col>

          <Col :span="8">
            <Form-item label="生产线代码" prop="productionLineCode">
              <Input
                v-model="purchaseList.productionLineCode"
                :placeholder="`${$t('common.inputInfo')}生产线代码`"
                type="number"
              ></Input>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="资产原值" prop="deviceOriginalPrice">
              <Input
                v-model="purchaseList.deviceOriginalPrice"
                :placeholder="`${$t('common.inputInfo')}资产原值`"
                type="number"
              ></Input>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="折旧年限" prop="depreciation">
              <Input
                v-model="purchaseList.depreciation"
                :placeholder="`${$t('common.inputInfo')}折旧年限`"
                type="number"
              ></Input>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="资产残值" prop="deviceResiduePrice">
              <Input
                v-model="purchaseList.deviceResiduePrice"
                :placeholder="`${$t('common.inputInfo')}资产残值`"
                type="number"
              ></Input>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="所在制程" prop="manufacturingProcess">
              <Input
                v-model="purchaseList.manufacturingProcess"
                :placeholder="`${$t('common.inputInfo')}所在制程`"
                type="number"
              ></Input>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="是否绑定盒子" prop="isBindBox">
              <Select
                v-model="purchaseList.isBindBox"
                filterable
                clearable
                :placeholder="`${$t('common.selectInfo')}是否绑定盒子`"
              >
                <Option value="是" label="是" />
                <Option value="否" label="否" />
              </Select>
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="所属公司" prop="company">
              <Input v-model="purchaseList.company" readonly type="text"></Input>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="成本中心" prop="costCenter">
              <Input
                v-model="purchaseList.costCenter"
                :placeholder="`${$t('common.inputInfo')}成本中心`"
                type="text"
              ></Input>
            </Form-item>
          </Col>

          <Col :span="8">
            <Form-item label="采购员" prop="purchaser">
              <Input
                v-model="purchaseList.purchaser"
                readonly
                :placeholder="`${$t('common.inputInfo')}采购员`"
                type="text"
              ></Input>
            </Form-item>
          </Col>

          <Col :span="8">
            <Form-item label="所属公司验收人" prop="checkAccepter">
              <Input
                v-model="purchaseList.checkAccepter"
                :placeholder="`${$t('common.inputInfo')}所属公司验收人`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="8">
            <Form-item label="转固日期" prop="toRegularDate">
              <Date-picker
                :value="purchaseList.toRegularDate"
                @on-change="(val) => {
                            purchaseList.toRegularDate = val
                        }"
                type="date"
                format="yyyy-MM-dd"
                :placeholder="`${$t('common.selectInfo')}转固日期`"
              />
            </Form-item>
          </Col>
          <Col :span="8">
            <Form-item label="品牌" prop="brand">
              <Input
                v-model="purchaseList.brand"
                :placeholder="`${$t('common.inputInfo')}品牌`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="24">
            <div class="list-layout list-layout1">
              <div class="btns clear">
                <span class="title title1">安装验收检测情况：</span>
                <Button @click="addClick">添加</Button>
              </div>
              <Table
                ellipsis
                ref="formTable"
                :border="false"
                size="small"
                :columns="addColumns"
                :data="purchaseList.itemList"
                @on-selection-change="handleSelectionChange"
              >
                <template slot-scope="{ index }" slot="acceptanceIndicators">
                  <Input
                    v-model="purchaseList.itemList[index].acceptanceIndicators"
                    :placeholder="`${$t('common.inputInfo')}验收指标`"
                    type="text"
                  ></Input>
                </template>

                <template slot-scope="{ index }" slot="standardRequirements">
                  <Input
                    v-model="purchaseList.itemList[index].standardRequirements"
                    :placeholder="`${$t('common.inputInfo')}标准要求`"
                    type="text"
                  ></Input>
                </template>

                <template slot-scope="{ index }" slot="testResult">
                  <Input
                    v-model="purchaseList.itemList[index].testResult"
                    :placeholder="`${$t('common.inputInfo')}测试结果`"
                    type="text"
                  ></Input>
                </template>
                <template slot-scope="{index }" slot="errorSituation">
                  <Input
                    v-model="purchaseList.itemList[index].errorSituation"
                    :placeholder="`${$t('common.inputInfo')}误差情况`"
                    type="text"
                  ></Input>
                </template>
                <template slot-scope="{ index }" slot="action" v-if="checkInfo == false">
                  <span
                    class="operationBtn"
                    @click="() => { purchaseList.itemList.splice(index, 1); }"
                  >
                    <i class="iconfont zy-common-shanchu"></i>
                    {{ $t('common.Delete') }}
                  </span>
                </template>
              </Table>
            </div>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col :span="24" class="mt16">
            <Form-item label="评价" prop="evaluate">
              <Input
                v-model="purchaseList.evaluate"
                :placeholder="`${$t('common.inputInfo')}评价`"
                type="text"
              ></Input>
            </Form-item>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button type="text" @click="onCancel">{{ $t('common.Cancle') }}</Button>
        <Button
          type="primary"
          :loading="delLoading"
          v-if="checkInfo == false"
          @click="okvisile"
        >提交验收</Button>
      </div>
    </Modal>
    <Modal :mask-closable="false" v-model="okVisible" title>
      <Row class="enableContent">
        <Col span="24" class="enableTips">
          <span>{{ $t('preliminary.p1') }}：{{ purchaseList.ebeln }}{{ $t('preliminary.p2') }}</span>
        </Col>
      </Row>
      <div slot="footer">
        <Button type="default" @click="okVisible = false">{{ $t('common.Cancle') }}</Button>
        <Button
          type="primary"
          :loading="delLoading"
          @click="okClick"
        >{{ $t('maintenance.Confirmed') }}</Button>
      </div>
    </Modal>
    <commonModal ref="commonModal"></commonModal>
    <inputModal ref="inputModal"></inputModal>
  </div>
</template>
  
<script>
import fileDownload from "js-file-download";
import addPurchaseModal from "./modules/addPurchaseModal";
import inputModal from "@/components/modalTypes/inputModal.vue";
import commonModal from "@/components/modalTypes/commonModal.vue";
import recursion from "@/util/recursion";
import { findOrgByToken, getDictData } from "@/api/index.js";
import toggleTableOperation from "@/mixins/toggleTableOperation";

export default {
  name: "picking",
  mixins: [toggleTableOperation],
  components: {
    addPurchaseModal,
    inputModal,
    commonModal
  },
  data() {
    return {
      deptList: [], //部门列表
      orgList: [], //功能位置
      addColumns: [
        {
          title: "验收指标",
          slot: "acceptanceIndicators",
          align: "center",
          minWidth: 130
        },
        {
          title: "标准要求",
          slot: "standardRequirements",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 150
        },
        {
          title: "测试结果",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 150,
          slot: "testResult"
        },
        {
          title: "误差情况",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 150,
          slot: "errorSituation"
        },
        {
          title: "操作",
          slot: "action",
          minWidth: 40,
          align: "center",
          resizable: true,
          tooltip: true
        }
      ],
      ids: [],
      okVisible: false,
      delLoading: false,
      checkInfo: false,
      dhzt: 0,
      arrivalStatusEnum: [
        {
          id: 0,
          name: this.$t("preliminary.ToBeArrived")
        },
        {
          id: 1,
          name: this.$t("preliminary.InArrival")
        },
        {
          id: 2,
          name: this.$t("preliminary.Arrived")
        }
      ],
      deviceType: [],
      deviceSource: [],
      addPurchaseFormRule: {
        deviceName: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        score: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "change",
            type: "number"
          }
        ],
        deviceNo: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        manufacture: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        deviceResiduePrice: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        checkAccepter: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        deviceWeight: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        specModel: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        factoryNo: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        standardRequirements: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],
        brand: [
          {
            required: true,
            message: `${this.$t("common.inputInfo")}`,
            trigger: "blur"
          }
        ],

        // testResult: [{ required: true, message: `${this.$t('common.inputInfo')}`, trigger: 'blur' }],
        // errorSituation: [{ required: true, message: `${this.$t('common.inputInfo')}`, trigger: 'blur' }],
        // acceptanceIndicators: [{ required: true, message: `${this.$t('common.inputInfo')}`, trigger: 'blur' }],
        // specModel: [{ required: true, message: `${this.$t('common.inputInfo')}`, trigger: 'blur' }],

        // checkAccepter: [{ required: true, message: `${this.$t('common.selectInfo')}`, trigger: 'change'}],
        // checkAccepter: [{ required: true, message: `${this.$t('common.selectInfo')}`, trigger: 'change'}],
        // checkAccepter: [{ required: true, message: `${this.$t('common.selectInfo')}`, trigger: 'change'}],
        installTime: [
          {
            required: true,
            message: `${this.$t("common.selectInfo")}`,
            type: "string"
          }
        ],
        functionLocation: [
          {
            required: true,
            message: `${this.$t("common.selectInfo")}`,
            trigger: "change",
            type: "array"
          }
        ],
        checkAcceptDate: [
          {
            required: true,
            message: `${this.$t("common.selectInfo")}`,
            type: "string"
          }
        ],
        manufacturDate: [
          {
            required: true,
            message: `${this.$t("common.selectInfo")}`,
            type: "string"
          }
        ],
        deviceCategory: [
          {
            required: true,
            message: `${this.$t("common.selectInfo")}`,
            trigger: "change"
          }
        ],
        evaluate: [
          {
            required: true,
            message: `${this.$t("common.selectInfo")}`,
            trigger: "change"
          }
        ]
      },
      purchaseList: {},
      textInfo: "新增",
      addStatus: false,
      personName: "",
      searchParams: {},
      total: 0,
      pageNum: 1,
      pageSize: 10,
      pageSizeOption: [10, 20, 30],
      checkAcceptStateList: [
        { value: "0", label: "未验收" },
        { value: "1", label: "已录入" },
        { value: "2", label: "已驳回" },
        { value: "3", label: "已完成" }
      ],
      statusList: [
        { id: 0, name: this.$t("preliminary.ToBeArrived") },
        { id: 1, name: this.$t("preliminary.InArrival") },
        { id: 2, name: this.$t("preliminary.Arrived") }
      ],
      columns: [
        {
          type: "selection",
          minWidth: 60,
          align: "center",
          fixed: "left"
        },
        {
          title: "验收状态",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 130,
          key: "checkAcceptState"
          // render: (h, params) => {
          //     return h('div', this.checkAcceptStateList.find((item) => { return item.value == params.row.checkAcceptState }).label)
          // },
        },
        {
          title: "资产编号",
          key: "assetCode",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 150
        },
        {
          title: "规格型号",
          key: "specModel",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 200
        },
        {
          title: "设备编号",
          key: "deviceCode",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 135
        },
        {
          title: "设备名称",
          key: "deviceName",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 150
        },
        {
          title: "设备类别",
          key: "deviceCategory",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 240
          // tooltip: true,
        },
        {
          title: "所属公司",
          key: "company",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 200
          // ellipsis: true
        },
        {
          title: "使用公司",
          key: "company1",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 200
          // ellipsis: true
        },
        {
          title: "供应商",
          key: "supplier",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 180
        },
        {
          title: "到位验收日期",
          key: "checkAcceptDate",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 180
        },
        {
          title: "所属公司验收人",
          key: "checkAccepter",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 150
        },
        {
          title: "采购员",
          key: "purchaser",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 135
        },
        {
          title: "驳回原因",
          key: "rejectReason",
          align: "center",
          resizable: true,
          tooltip: true,
          minWidth: 135
        },
        {
          title: "操作",
          slot: "action",
          minWidth: 350,
          align: "center",
          fixed: "right"
        }
      ],
      requestProject: {
        itemList: []
      },
      dataSource: [],
      dateTimeRange: [],
      editStatus: false,
      OAList: []
    };
  },
  created() {
    this.changeNum();
    this.searchList();
    this.getdeptList();
    this.getOrgList();
    getDictData("设备类别").then(res => {
      this.deviceType = res.data;
    });
    getDictData("设备来源").then(res => {
      this.deviceSource = res.data;
    });
  },
  mounted() {
    this.getTableColumnsWidth(this.columns, "orderAdjustmentDeviceInfo");
  },
  beforeRouteLeave(to, from, next) {
    if (to.name == "detailPurchaseModal") {
      from.meta.keepAlive = true;
    } else {
      from.meta.keepAlive = false;
    }
    next();
  },
  methods: {
    getdeptList() {
      this.deptList = [];
      let data = {
        pageNo: 1,
        pageSize: 100
      };
      this.axios({
        method: "post",
        url: "/basic/dept/list",
        data
      }).then(res => {
        if (res.code === 200) {
          this.deptList = res.data.list;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true
          });
        }
      });
    },
    reset() {
      this.searchParams = {};
      this.changeNum();
    },
    addClick() {
      let obj = {
        acceptanceIndicators: "",
        errorSituation: "",
        standardRequirements: "",
        testResult: ""
      };
      this.purchaseList.itemList.push(obj);
    },
    addClickinfo(row, type) {
      this.checkInfo = type;
      this.addStatus = false;
      if (row.checkAcceptState == "未验收") {
        this.purchaseList = {
          ...row,
          installTime: "",
          manufacturDate: "",
          toRegularDate: "",
          itemList: [],
          isBindBox: "否",
          company: row.company
        };
        this.purchaseList.checkAcceptId = this.purchaseList.id;
        delete this.purchaseList.id;
        this.textInfo = `${this.$t("common.New")}`;
        this.editStatus = false;
        this.addStatus = true;
      } else {
        this.axios({
          method: "GET",
          url: "/dms/deviceCheckAccept/selectCheckDetailById",
          params: { id: row.id }
        }).then(res => {
          if (res.code === 200) {
            this.purchaseList.checkAcceptId = row.id;
            this.purchaseList = {
              ...res.data
            };
            this.addStatus = true;
          } else {
            this.$Message.warning({
              content: res.msg,
              duration: 6,
              closable: true
            });
          }
        });
        this.textInfo = `${this.$t("common.Edit")}`;
      }
    },
    addViseChange() {
      if (!this.addStatus) {
        this.$refs["purchaseForm"].resetFields();
      }
    },
    onCancel() {
      this.addStatus = false;
      //this.$refs['purchaseForm'].resetFields()
    },
    clickRow(row, status) {
      const that = this;
      this.row = row;
      let personnel = window.localStorage.getItem("ziyunFactoryPortalName");
      if (status == "rej") {
        this.$refs.inputModal.showModal({
          title: "驳回",
          submit: form => {
            this.axios({
              method: "put",
              url: "/dms/deviceCheckAccept/reject",
              data: { id: row.id, rejectReason: form.value }
            }).then(res => {
              if (res.code === 200) {
                this.$Message.success(res.msg);
                this.searchList();
              } else {
                this.$Message.warning({
                  content: res.msg,
                  duration: 6,
                  closable: true
                });
              }
            });
          }
        });
      } else if (status == "comp") {
        this.$refs.commonModal.showModal({
          title: "完成提醒",
          type: "sure",
          desc: "是否确认设备验收完成？",
          submit: () => {
            this.axios({
              method: "put",
              url: "/dms/deviceCheckAccept/pass",
              params: { id: row.id }
            }).then(res => {
              if (res.code === 200) {
                this.$Message.success(res.msg);
                this.searchList();
              } else {
                this.$Message.warning({
                  content: res.msg,
                  duration: 6,
                  closable: true
                });
              }
            });
          }
        });
      }
    },
    handlefhBeforeUpload() {},
    changeMenge() {
      this.purchaseList.wdhzs = this.purchaseList.menge;
    },
    okvisile() {
      const { purchaseList } = this;
      if (purchaseList.itemList.length == 0) {
        this.$Message.error("最少输入一条安装验收检测情况");
        return;
      }
      for (let index = 0; index < purchaseList.itemList.length; index++) {
        const element = purchaseList.itemList[index];
        for (let v in element) {
          if (element[v] == "") {
            this.$Message.error("请输入安装验收检测情况");
            return;
          }
        }
      }
      this.delLoading = true;
      this.$refs.purchaseForm
        .validate(valid => {
          if (valid) {
            this.axios({
              method: "post",
              url: "/dms/deviceCheckAccept/checkAccept",
              data: this.purchaseList
            }).then(res => {
              if (res.code === 200) {
                this.searchList();
                this.$Message.success({
                  content: res.msg,
                  duration: 6,
                  closable: true
                });
                this.delLoading = false;
                this.addStatus = false;
              } else {
                this.$Message.warning({
                  content: res.msg,
                  duration: 6,
                  closable: true
                });
              }
            });
          } else {
            this.$Message.error(this.$t("preliminary.p4"));
          }
        })
        .finally(() => {
          this.delLoading = false;
        });
    },
    //日期
    handleChangeDate(val) {
      this.searchParams.beginDate = val[0];
      this.searchParams.endDate = val[1];
      // this.searchParams.cdate = val ? this.$moment(val).format('YYYY-MM-DD') : ''
    },
    //采购录入
    sendClick(record) {
      this.$refs.addPurchaseModal.show(record);
    },
    //查看
    lockClick(record) {
      this.$router.push({
        path: "/devBasic/earlierStage/detailPurchaseModal",
        query: {
          requestNo: record.banfn,
          requestProject: record.bnfpo,
          orderNo: record.ebeln,
          orderProject: record.ebelp,
          werksName: record.werksName,
          id: record.id
        }
      });
    },
    //刷新
    handleRefresh() {
      this.searchList();
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },
    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },
    searchList() {
      //查询列表
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      };
      for (let key in this.searchParams) {
        if (this.searchParams[key] || key == "dhzt") {
          this.$set(params, key, this.searchParams[key]);
        }
      }
      this.axios({
        method: "POST",
        url: "/dms/deviceCheckAccept/page",
        data: params
      }).then(res => {
        if (res.code === 200) {
          this.dataSource = res.data.records;
          this.total = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true
          });
        }
      });
    },
    handleSelectionChange(selectionData) {
      console.log(selectionData);
      let arr = [];
      selectionData.forEach(item => {
        arr.push(item.id);
      });
      this.ids = arr;
    },
    //导出
    exportTemplateClick() {
      let params = {
        pageNo: this.pageNum,
        pageSize: this.pageSize,
        dmsPurchaseIdList: this.ids
      };
      for (let key in this.searchParams) {
        if (this.searchParams[key] || key == "dhzt") {
          this.$set(params, key, this.searchParams[key]);
        }
      }
      const filName = "设备采购";
      this.axios({
        method: "post",
        url: "/dms/dmsPurchase/export",
        responseType: "blob",
        data: params
      }).then(res => {
        fileDownload(res, filName + ".xlsx");
      });
    },
    getOrgList() {
      let params = {
        level: 0
      };
      findOrgByToken(params).then(res => {
        if (res.code === 200) {
          const obj = {
            label: "name",
            value: "code",
            children: "children"
          };
          this.orgList = recursion.convertTree(res.data, obj);
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true
          });
        }
      });
    },
    getOAList(query) {
      if (typeof query === "string" && query.indexOf("----") > 0) {
        return;
      }
      if (query !== "") {
        this.axios({
          method: "get",
          url: "/basic/user/searchOAUser",
          params: {
            key: query
          }
        }).then(res => {
          if (res.code === 200) {
            this.OAList = res.data.map(item => {
              return {
                ...item,
                showName: item.empno + "----" + item.username
              };
            });
          } else {
            this.OAList = [];
            this.$Message.warning({
              content: res.msg,
              duration: 6,
              closable: true
            });
          }
        });
      }
    }
  }
};
</script>
  
<style scoped lang="scss">
.title1 {
  padding-bottom: 0;
  font-size: 14px;
  font-weight: 400;
  color: #00142d;
  display: block;
  text-align: left;
}

.list-layout1 {
  padding: 0px !important;
  border-radius: 0 !important;
  box-shadow: 0 !important;
}
</style>
  
  
  